package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @ApiOperation("新增套餐")
    @PostMapping
    public Result<Object> addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("<UNK>setmealDTO:{}",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("<UNK>pageQueryDTO:{}",setmealPageQueryDTO);
        return  Result.success(setmealService.pageQuery(setmealPageQueryDTO));
    }

    @DeleteMapping
    @ApiOperation("批量删除")
    public Result<Object> deleteBench(@RequestParam List<Long> ids){
        log.info("<UNK>deleteSetmeal");
        setmealService.deleteBench(ids);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改")
    public Result<Object> update(@RequestBody SetmealDTO setmealDTO){
        log.info("<UNK>updateSetmeal{}",setmealDTO);

        setmealService.update(setmealDTO);
        return Result.success();


    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> getSetmealById(@PathVariable Long id){
        log.info("<UNK>getSetmealById:{}",id);

        return Result.success(setmealService.getSetmealById(id));
    }

    @PostMapping("/status/{status}")
    public Result<Object> startOrStop(@PathVariable Integer status,Long id){
        log.info("<UNK>startOrStop:{}",status);
        setmealService.startOrStop(status,id);
        return Result.success();
    }

}
